/*
** disconnect_socket.c for  in /home/faye_m//tmp/zappy-2011/new_server/src/zappy-2011/new_server/src
** 
** Made by mouhamed faye
** Login   <faye_m@epitech.net>
** 
** Started on  Sun Jul 10 11:58:32 2011 mouhamed faye
** Last update Sun Jul 10 22:16:48 2011 vincent ricard
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "types.h"

void	disconnect_socket(T_env *e)
{
  Find_disconnected_socket(e);
  close(e->i);
  FD_CLR(e->i, &e->master);
}

int Find_disconnected_socket(T_env *e)
{
  int i;

  i = 0;
  while (i < getMaxFd())
    {
      if (e->tab[i] == e->i)
	{
	  e->tab[i] = 0;
	  return 1;
	}
      ++i;
    }
  return 0;
}

int Find_first(T_env *e)
{
 int i;

  i = 0;
  while (i < getMaxFd())
    {
      if (e->tab[i] == 0)
	{
	  e->inc = i;
	  return 1;
	}
      ++i;
    }
  return 0;
}
